﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            /*int x = Plus(1, 2);
int y = Plus(x, 3);
int z = Plus(y, 4);
int k = Plus(z, 5);
int l = Plus(k, 6);*/


            ArrayList ar = new ArrayList { 1, 2, 3, 4, 5, 6 };
            int x = 21;
            ArrayList res = new ArrayList();
            res.Add(1);
            for (int i = 1; i < ar.Count; i++)
            {
                int N = (int)ar[i];
                res = DoMaths(ar, N, res);
            }
            int count = 0;
            for (int j = 0; j < res.Count; j++)
            {
                if ((int)res[j] == x)
                {
                    count++;
                }
            }
            Console.WriteLine(count);
            ArrayList indexAr = GetIndexes(x, res);
            ArrayList operatorsAll = FindOperators(ar, res, indexAr);
            foreach (var el in operatorsAll)
            {
                Console.WriteLine(el);
            }

 
           /* foreach (var el in indexAr)
            {
                Console.WriteLine(el);
            }*/
        }

        static public ArrayList DoMaths(ArrayList ar, int N, ArrayList res)
        {
            ArrayList resCopy = new ArrayList();

            foreach (var el in res)
            {
                resCopy.Add(el);
            }
            res.Clear();
            foreach (int el in resCopy)
            {

                res.Add(el + N);
                res.Add(el - N);
                res.Add(el / N);
                res.Add(el * N);
            }

            return res;
        }

        static public ArrayList GetIndexes(int x, ArrayList res)
        {
            ArrayList indexAr = new ArrayList();
            for (int i=0; i<res.Count; i++)
            {
                int index = (int)res[i];
                if (index == x)
                {
                    indexAr.Add(i);
                }
            }
            return indexAr;
        }

        static public ArrayList FindOperators(ArrayList ar, ArrayList res, ArrayList indexAr) // передаю индекс инта в массиве результатов
        {
            ArrayList operators = new ArrayList();
             
            foreach(int elem in indexAr)
            {
                int numElemInGroup = res.Count / 4;
                int index = elem;
            for (int i = 0; i < ar.Count - 1; i++)
            {
                if (index >= 0 && index < numElemInGroup)
                {
                    operators.Add("+");
                }
                else if (index >= numElemInGroup && index < numElemInGroup*2)
                {
                    operators.Add("-");
                }
                else if (index >= numElemInGroup*2 && index < numElemInGroup * 3)
                {
                    operators.Add("*");
                }
                else if (index >= numElemInGroup * 3 && index < numElemInGroup * 4)
                {
                    operators.Add("/");
                }
                numElemInGroup = numElemInGroup / 4;

            }
            //operatorsAll.Add(operators);

            }

            return operators;
        }

    }
}